<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>登录成功</title>
    <style>
        body { font-family: Arial, sans-serif; text-align: center; margin-top: 80px; }
        .success { color: #4CAF50; font-size: 1.5em; }
        .desc { margin-top: 20px; color: #888; }
    </style>
</head>
<body>
    <div class="success">登录成功</div>
    <div class="desc" id="desc">正在处理登录…</div>
    <script>
        window.onload = function() {
            try {
                const sessionId = "{{ current_session }}";
                if (window.opener && window.opener !== window) {
                    // 使用 postMessage 发送 sessionId 到主窗口, 兼容 Electron 没有域名的情况
                    window.opener.postMessage({type: 'auth_success', sessionId: sessionId}, '*');
                    document.getElementById('desc').innerText = "登录成功，窗口即将自动关闭…";
                    setTimeout(window.close, 1500);
                } else {
                    console.warn('未找到 window.opener 或 opener 等于自身，无法 postMessage。');
                    document.getElementById('desc').innerText = "登录成功，但未能自动返回主页面，请手动关闭本窗口。";
                }
            } catch (e) {
                console.error("postMessage 脚本出错:", e);
                document.getElementById('desc').innerText = "登录流程发生异常，请关闭本窗口并重试。";
            }
        };
    </script>
</body>
</html>
